//
//  GRUserManager.m
//  test
//
//  Created by 朱圳 on 2018/1/13.
//  Copyright © 2018年 朱圳. All rights reserved.
//
#define User @"User"
#import "GRUserManager.h"

@implementation GRUserManager
//偏好设置（preference）
//保存
+(void)save:(GRUserModel *)user{
    
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    /****************学生***************************/
//     [userDefaults setObject:user.name forKey:@"name"];
//     [userDefaults setObject:user.sex forKey:@"sex"];
//     [userDefaults setObject:user.phone forKey:@"phone"];
    
    [userDefaults setObject:user.birthday forKey:@"birthday"];
    [userDefaults setObject:user.dadphone forKey:@"dadphone"];//爸爸电话
     [userDefaults setObject:user.college forKey:@"college"];
     [userDefaults setObject:user.jbirthday forKey:@"jbirthday"];
     [userDefaults setObject:user.jid forKey:@"jid"];
     [userDefaults setObject:user.jieshu forKey:@"jieshu"];
    /****************教务老师***************************/
    [userDefaults setObject:user.jname forKey:@"jname"];
    [userDefaults setObject:user.jphone forKey:@"jphone"];
    [userDefaults setObject:user.jqq forKey:@"jqq"];
    [userDefaults setObject:user.jwechat forKey:@"jwechat"];
    [userDefaults setObject:user.mumphone forKey:@"mumphone"];
    [userDefaults setObject:user.pic forKey:@"grpic"];
    /****************专业老师***************************/
    [userDefaults setObject:user.name forKey:@"name"];

    [userDefaults setObject:user.phone forKey:@"phone"];
    [userDefaults setObject:user.pic forKey:@"pic"];
     [userDefaults setObject:user.qnumber forKey:@"qnumber"];
     [userDefaults setObject:user.sex forKey:@"sex"];
     [userDefaults setObject:user.time forKey:@"time"];
    [userDefaults setObject:user.wnumber forKey:@"wnumber"];
    
    [userDefaults setObject:user.gid forKey:@"gid"];
    [userDefaults setObject:user.password forKey:@"gpassword"];
    
    [userDefaults removeObjectForKey:@"classification"];//先移除
    [userDefaults setObject:user.classification forKey:@"classification"];//再添加
    
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user];
    [userDefaults setObject:data forKey:User];
    //立即同步
    [userDefaults synchronize];
}

+(GRUserModel *)me{
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    NSData *data = [userDefaults objectForKey:User];
    GRUserModel *user = nil;
    if (data) {
        user = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    }
    return user;
}

+(void)loginOut{
    
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    [userDefaults removeObjectForKey:User];
    [userDefaults removeObjectForKey:@"name"];
    [userDefaults removeObjectForKey:@"classification"];
}

+(BOOL)isGRLogining{
    
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    NSString *userName = [userDefaults objectForKey:@"name"];
    NSString *classification = [userDefaults objectForKey:@"classification"];
    
    if (userName && classification) {
        return YES;
    }else{
        return NO;
    }
}
@end
